package com.rxjava.retrofit;

import java.io.IOException;
import java.util.List;

import com.google.gson.Gson;

import retrofit2.Call;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;
import rx.Observable;

//http://square.github.io/retrofit/
public class RetrofitDemo {
	public static void main(String[] args) throws IOException {
		Retrofit retrofit = new Retrofit.Builder().baseUrl(
				"https://api.github.com/")
				.addCallAdapterFactory(RxJavaCallAdapterFactory.create()) // 使用RxJava作为回调适配器
				.addConverterFactory(GsonConverterFactory.create())
				.build();

		GitHubService service = retrofit.create(GitHubService.class);
		
//		//callback 调用  
//		Call<List<Repo>> repos = service.listRepos("octocat");
//		List<Repo> list = repos.execute().body();
//		for (Repo repo : list) {
//			System.out.println(new Gson().toJson(repo));
//		}
		
		
		//rxjava 调用 
		service.list("octocat").flatMap(s->Observable.from(s)).subscribe(s->System.out.println(new Gson().toJson(s)));
	}
}
